package com.gmail.blackdog1987.onedollar.dao;

import com.gmail.blackdog1987.onedollar.dao.hibernate.EntityHibernateDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.BaseJdbcDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.JdbcUtil;
import com.gmail.blackdog1987.onedollar.entity.TGoodsOnedollarEntity;
import com.gmail.blackdog1987.onedollar.entity.TGoodsParamEntity;
import com.gmail.blackdog1987.onedollar.entity.TLuckybagConsumeEntity;
import com.gmail.blackdog1987.onedollar.entity.base.Page;
import com.gmail.blackdog1987.onedollar.vo.GoodsVO;
import com.gmail.blackdog1987.onedollar.vo.LuckyBagVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Repository("goodsOneDollarDao")
public class GoodsOneDollarDao extends EntityHibernateDao<TGoodsOnedollarEntity>{
    @Autowired
    BaseJdbcDao baseJdbcDao;
    public List<TGoodsOnedollarEntity> queryForReset(Date time){
        String selectionSql = "select distinct * from t_goods_onedollar where id in (select onedollar_id from t_order_onedollar where user_id is not null and pay_status = 0 and createtime < ?)";
        return JdbcUtil.queryForList(baseJdbcDao, TGoodsOnedollarEntity.class, selectionSql, new Object[]{time});
    }

    public List<TGoodsOnedollarEntity> queryForFinish(Date time){
        String selectionSql = "select * from t_goods_onedollar where need=fill and endtime is null";

        return JdbcUtil.queryForList(baseJdbcDao, TGoodsOnedollarEntity.class, selectionSql, new Object[]{});
    }

    public List<TGoodsOnedollarEntity> queryForNotFinish(Date time){
        String selectionSql = "select * from t_goods_onedollar where totime >= ? and fill>=need";

        return JdbcUtil.queryForList(baseJdbcDao, TGoodsOnedollarEntity.class, selectionSql, new Object[]{time});
    }
}
